rankingListController = BaseController.extend({
	template:'rankingList',
	center:'英雄榜',
	mainView: 'rankingList',
	bottomShow:true,
	rankingListData:new ReactiveVar([]),
	goodsListData:new ReactiveVar([]),
	waitOn:function(){
		let self = this;
		self.partner = self.currentUser();
		var arr = [];
		//获取在售商品列表
		self.get('common/get-partner-goods',{partner_id:self.partner.id,level_name:self.partner.level_name,limit:100}).then(function(res){
				//var arr = [];
				var data = res.data;
				for(var i in data){
					arr.push(data[i])
				}
				self.goodsListData.set(arr);
				console.log('sold goods:' + arr.length);
			if (arr.length !== 0){
				var goods_id = arr[0].id;
				self.get('common/get-goods-rank',{goods_id:goods_id,level_name: self.partner.level_name}).then(function(res){					
					var data = res.data;
					var ranks = [];
					console.log(res.data);
					for(var i in data){
						ranks.push(data[i])
					}
					console.log('ranking list:' + ranks.length);
					console.log(ranks);
					self.rankingListData.set(ranks);
				},function(err){
					console.log(err)
				})
		}
			},function(err){
				console.log(err)
			})	

		
		this.selector = new ReactiveVar();
		this.selector.set({});
	},
	onRendered:function(self){
		self.partner = self.currentUser();
		/*捕获商品名*/
		var selectors = {};
		$('#sid').change(function(){
			var selectValue = $('#sid').val();
			selectors.goods_id = parseInt(selectValue);
			goods_id = parseInt(selectValue);
			self.get('common/get-goods-rank',{goods_id:goods_id,level_name: self.partner.level_name}).then(function(res){					
					var data = res.data;
					var ranks = [];
					for(var i in data){
						ranks.push(data[i])
					}
					self.rankingListData.set(ranks);
				},function(err){
					console.log(err)
				})
			self.selector.set(selectors);
		});
	},
	data: function(){
		let self = this;
		self.partner = self.currentUser();
		return {
			ranking: function(){
				//获取该商品的排行榜
				return self.rankingListData.get();
			},
			getGoods: function(){
				return self.goodsListData.get();
			},
		}
	}
})